from pathlib import Path


def get_project_root():
    """获取项目根目录"""
    # 从当前文件开始向上查找
    current = Path(__file__).resolve()

    # 查找常见的项目根目录标识
    root_markers = [
        'pyproject.toml',
        'setup.py',
        'requirements.txt',
        '.git',
        '.project_root',  # 可以手动创建一个空文件作为标记
    ]

    while current != current.parent:
        if any((current / marker).exists() for marker in root_markers):
            return current
        current = current.parent

    # 如果没找到，返回当前文件所在目录作为备选
    return Path(__file__).resolve().parent


